<template>
  <div class="p-2">

    <div class="mb-[10px]">
      <el-card>
        <el-form
          ref="queryFormRef"
          :model="queryParams"
          :inline="true"
          label-width="auto"
        >
          <el-form-item
            label="创建时间"
          >
            <el-date-picker
              v-model="dateRange"
              value-format="YYYY-MM-DD"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 240px"
            ></el-date-picker>
          </el-form-item>
          <el-form-item
            label="企业编码"
            prop="no"
          >
            <el-input
              v-model="queryParams.no"
              placeholder="请输入企业编码"
              clearable
              style="width: 240px"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item
            label="企业名称"
            prop="name"
          >
            <el-input
              v-model="queryParams.name"
              placeholder="请输入企业名称"
              clearable
              style="width: 240px"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              @click="handleQuery"
              icon="Search"
            >查询</el-button>
            <el-button
              @click="resetQuery"
              icon="Refresh"
            >重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <el-card>
      <el-table
        v-loading="loading"
        :data="enterpriseList"
        border
      >
        <el-table-column
          label="创建时间"
          align="center"
          min-width="160"
          prop="createTime"
        />
        <el-table-column
          label="企业名称"
          align="center"
          min-width="160"
          prop="name"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="企业编码"
          align="center"
          min-width="160"
          prop="no"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="所属代理商"
          align="center"
          min-width="160"
          prop="agentName"
        />
        <el-table-column
          label="所属代理商编号"
          align="center"
          min-width="160"
          prop="agentNo"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="所属运营商"
          align="center"
          min-width="160"
          prop="operatorName"
        />
        <el-table-column
          label="所属运营商编号"
          align="center"
          min-width="160"
          prop="operatorNo"
        />
        <el-table-column
          label="审核状态"
          align="center"
          min-width="160"
          prop="verifyStatusName"
        />

        <el-table-column
          label="操作"
          fixed="right"
          align="center"
          width="120"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <el-tag
              link
              type="success"
              @click="productConfig(scope.row)"
              v-hasPermi="['payment:merchantProduct:add']"
            >产品配置</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script setup name="productConfiguration" lang="ts">
import addEnterpriseApi from '@/api/enterprise/addEnterprise';
import api from '@/api/enterprise/productConfiguration';
import { EnterpriseQuery, EnterpriseVO } from '@/api/enterprise/addEnterprise/types';
import { SalesmanVO } from '@/api/system/salesman/types';

const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const enterpriseList = ref<EnterpriseVO[]>();
const loading = ref(true);
const total = ref(0);
const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
const queryFormRef = ref<ElFormInstance>();
const queryParams = ref<EnterpriseQuery>({
  pageNum: 1,
  pageSize: 10,
  isProduct:1,
  name: '',
  no: ''
});

/** 查询企业列表 */
const getList = async () => {
  loading.value = true;
  const res = await addEnterpriseApi.enterpriseList(proxy?.addDateRange(queryParams.value, dateRange.value));
  loading.value = false;
  enterpriseList.value = res.rows;
  total.value = res.total;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
  dateRange.value = ['', ''];
  queryFormRef.value?.resetFields();
  queryParams.value.pageNum = 1;
  handleQuery();
};

/** 产品配置 */
const productConfig = (row: any) => {
  router.push( 'productConfig?id=' + row.id + '&no=' + row.no + '&name=' + row.name);
};

onMounted(() => {
  getList(); // 初始化列表数据
});
</script>

<style lang="scss" scoped></style>
